package com.yanxibao.controller;

import com.yanxibao.bean.History;
import com.yanxibao.common.Result;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.HistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 历史;(_history)表控制层
 *
 * @author kongke
 * @date 2023/11/16
 */
@Slf4j
@Api(tags = "历史对象功能接口")
@RestController
@CrossOrigin
@RequestMapping("/History")
public class HistoryController {

    @Resource
    private HistoryService historyService;


    /**
     * 通过ID查询单条数据
     */
    @ApiOperation("通过ID查询数据")
    @GetMapping("/getById/{id}")
    public Result<History> queryById(@PathVariable Integer id) {
        return historyService.queryById(id);
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/getPage")
    @ResponseBody
    public Result<PageQueryDTO<History>> pageQuery(@RequestParam("current") Integer current,
                                                   @RequestParam("size") Integer size,
                                                   @RequestBody History history) {

        return historyService.pageQuery(history, current, size);
    }

    /**
     * 新增数据
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public Result<History> add(@RequestBody History history) {
        return historyService.insert(history);
    }

    /**
     * 更新数据
     */
    @ApiOperation("更新数据")
    @PutMapping("/update")
    public Result<History> update(@RequestBody History history) {
        return historyService.update(history);
    }


    /**
     * 通过主键删除数据
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/del/{id}")
    public Result<Boolean> deleteById(@PathVariable Integer id) {
        return historyService.deleteById(id);
    }
}